<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
    <link rel="stylesheet" href="../../static/admin/element-ui/lib/theme-chalk/index.css">
    <script src="../../static/admin/js/vue.js"></script>
    <script src="../../static/admin/element-ui/lib/index.js"></script>
    <script src="../../static/admin/js/axios-0.18.0.js"></script>


</head>
<body>
<div id="div">


    <div class="app-container">


        <div class="box common-search-border2">
            <div class="filter-container">

                <!--
                    :inline="true	行内表单模式 (表单项横向排列)
                    :model="queryParams"  数据绑定
                    ref="queryParams" 用于找到本表单使用
                -->
                <el-form :inline="true" :model="userId" ref="userId"
                         class="formInfo">
                    <el-form-item label="用户ID" label-width="80px">
                        <el-input placeholder="请输入" v-model="userId"
                                  style="width: 200px;" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest">清除</el-button>
                        <el-button type="primary" class="butOK" @click="handleSearch">搜索</el-button>
                    </el-form-item>
                </el-form>

                <el-button class="butDelete" type="danger" @click="handleDelete(clientData)"> 批量删除
                </el-button>
                <el-dialog title="删除" :visible.sync="deleteUserFormVisible" width="30%" class="deleteUserForm">
                    <span>用户删除后不可恢复,是否继续?</span>
                    <span slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="deleteUserFormVisible = false">取 消</el-button>
                        <el-button size="mini" type="primary" @click="submitDeleteUser">确 定</el-button>
                    </span>
                </el-dialog>
            </div>


        </div>
        <div class="box common-table-border" style="margin:8px 0 0;">
            <!--

            -->
            <!--
                data	显示的数据
                fit	列的宽度是否自撑开
            -->

            <el-table
                    :data="logList"
                    ref="multipleTable"
                    fit
                    tooltip-effect="dark"
                    style="width: 100%;"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>

                <el-table-column label="日志编号" width="50px" align="center" prop="id">
                </el-table-column>
                <el-table-column label="用户id" align="center" prop="userId">
                </el-table-column>
                <el-table-column label="日志类型" align="center" prop="type">
                </el-table-column>
                <el-table-column label="位置" align="center" prop="place">
                </el-table-column>
                <el-table-column label="登陆设备" align="center" prop="equipment">
                </el-table-column>
                <el-table-column label="记录时间" align="center" prop="logTime">
                </el-table-column>
                <el-table-column label="操作" width="90">
                    <template slot-scope="scope">

                        <div class="operation" v-if="scope.row.name != '管理员'">
                            <el-button size="mini" type="danger" @click="handleDeleted(scope.row)"> 删除
                            </el-button>
                        </div>
                    </template>
                </el-table-column>

            </el-table>
            <!--

                   @size-change： 当改变每页条数时触发的函数
                   @current-change：当改变页码时触发的函数
                   current-page ：默认的页码
                   :page-sizes：每页条数选择框中显示的值
                   :page-size : 默认的每页条数
                   layout： 分页组件的布局
                       total（总条数）, sizes(每页条数), prev（上一页）, pager(所有的页码), next(下一页), jumper（跳转页码）
                   :total: 总条数
             -->
            <div style="text-align: center">
                <!--分页组件-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageNum"
                        :page-sizes="[15, 30, 60]"
                        :page-size="pagination.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
        </div>

    <!-- end -->
</div>

</div>

</body>
<script>

    let app = new Vue({
        el: "#div",
        data: {

            pagination: {},
            userId: "",
            logList: [], // 角色列表数据
            logIds: [],
            multipleSelection: [],
            deleteUserFormVisible: false,

        },


        methods: {
            //搜索
            handleSearch() {
                //将当前页码设置为1
                this.pagination.pageNum = 1;
                this.getRoleList();
            },

            // 获取日志分页数据
            getRoleList() {

                axios.get("/findLogList", {
                    params: {
                        "userId": this.userId,
                        "pageNum": this.pagination.pageNum,
                        "pageSize": this.pagination.pageSize
                    }
                }).then(resp => {
                    this.pagination = resp.data;
                    this.logList = resp.data.items;
                });

            },
            //删除日志
            handleDeleted(row) {
                axios.delete("/deleteLogById?id=" + row.id).then(resp => {
                    this.getRoleList();
                });
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            //将查询条件置空
            handleRest() {
                this.userId = ''
            },


            // 批量删除数据
            handleDelete(rows) {
                this.deleteUserFormVisible = true;
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    let j = i;
                    let id = this.multipleSelection[j].id;
                    this.logIds.push(id);
                }
//this.deleteIds 要删除的数据的id数组
                this.logIds = this.logIds.toString();
            },

// 提交删除用户
            submitDeleteUser() {
                this.deleteUserFormVisible = false;

//clientDelete为接口
                axios.delete("/deleteLog?ids=" + this.logIds).then(res => {
                    this.getRoleList();
                    this.logIds = [];
                    if (res.data === "0000") {
                        this.$message.success("success");
                    } else {
                        this.$message.error(res.data);
                    }
                    this.reload();

                });
            },
            //当前页改变时调用的方法
            handleCurrentChange(pageNum, pageSize) {
                //将最新页码赋值给分页对象的当前页码
                this.pagination.pageNum = pageNum;
                this.pagination.pagesize = pageSize;
                //重新发起分页请求
                this.getRoleList();
            },
            //改变每页大小时调用的方法
            handleSizeChange(pageSize) {
                //将最新的每页大爱小赋值给分页对象的当前页码
                this.pagination.pageSize = pageSize;
                //重新发起分页请求
                this.getRoleList();
            },

        },

        created() {
            //分页查询日志列表
            this.getRoleList();
        },


    })
</script>
</html>